package com.xiaoma.thread;

/**
 * https://www.cnblogs.com/54chensongxia/p/12015443.html?share_token=1CC42E8A-BB73-4E3D-B64C-48819842A535&tt_from=copy_link&utm_source=copy_link&utm_medium=toutiao_ios&utm_campaign=client_share
 */
public class InheritableThreadLocalDemo {

  private static InheritableThreadLocal<String> threadLocal = new InheritableThreadLocal<>();
//父线程传递本地变量到子线程的解决方式及分析
  public static void main(String[] args) {
    threadLocal.set("mainThread");
    System.out.println("value:"+threadLocal.get());
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        String value = threadLocal.get();
        System.out.println("value:"+value);
      }
    });

    thread.start();
  }
}
